<script>
	var dbshop_com_error = '<?php echo $this->translate('两次输入的密码不一致！'); ?>';
</script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/artDialog.js?skin=simple'); ?>"></script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/plugins/iframeTools.js'); ?>"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->basePath('public/css/dbblack/js/form/style.css'); ?>"/>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/form/form.js'); ?>"></script>

<div class="magic-bg right" >
	<?php if ($this->frontwebsite()->getUserIni('user_register_state') == 'true') { ?>
		<div class="simple-box "  style="width:480px;height:540px;left:18%">
			<div class="title">
				<div class="sub-1"><h1><?php echo $this->translate('用户注册'); ?></h1></div><div class="sub-2"><a href="<?php echo $this->url('frontuser/default',array('action'=>'login')); ?>"><?php echo $this->translate('会员登录'); ?></a></div>
			</div>
			<form class="reg-box" method="post" callback="checkReadme">
				<input type="hidden" name="http_referer" value="<?php echo $this->http_referer; ?>" />
				<input type="hidden" name="<?php echo $this->register_csrf['name']; ?>" value="<?php echo $this->register_csrf['value']; ?>" />
				<ul class="form">
					<li>
						<span class="perfix fa">&#xf007;</span><input name="user_name" id="user_name"  class="input" pattern="required" placeholder="<?php echo $this->translate('输入会员名称'); ?>" alt="请输入会员名称!">
					</li>
					<li>
						<span class="perfix fa">&#xf023;</span><input bind="user_com_passwd" minlen=6 maxlen=20 class="input" type="password" name="user_password" pattern="required" placeholder="密码" alt="6-20任意字符组合">
					</li>
					<li>
						<span class="perfix fa">&#xf084;</span><input bind="user_password" minlen=6 maxlen=20 class="input" type="password"  name="user_com_passwd" pattern="required" placeholder="确认密码" alt="6-20任意字符组合">
					</li>
					<?php
					$userEmailRegisterState = $this->frontwebsite()->getRegOrLoginIni('register_email_state');
					$userPhoneRegisterState = $this->frontwebsite()->getRegOrLoginIni('register_phone_state');

					$userPhoneCaptchaState = $this->frontwebsite()->websiteCaptchaState('phone_user_register_captcha');
					?>
					<?php if ($userEmailRegisterState == 'true') { ?>
						<li>
							<span class="perfix fa">&#xf003;</span><input name="user_email" id="user_email"  class="input" pattern="email" placeholder="<?php echo $this->translate('输入电子邮件'); ?>" alt="邮箱格式不正确!">
						</li>
					<?php } ?>
					<?php if ($userPhoneRegisterState == 'true') { ?>
						<li>
							<span class="perfix fa">&#xf10b;</span><input name="user_phone" id="user_phone"  class="input" pattern="phone" placeholder="<?php echo $this->translate('输入手机号码'); ?>" alt="手机号码格式不正确!">
						</li>
						<?php if($userPhoneCaptchaState == 'true') { ?>
							<li>
								<span class="perfix fa">&#xf02a;</span><input type="text" class="input-sm" name="phone_captcha" id="phone_captcha" maxlength="6" style="width: 80px;" pattern="\w{6}" alt="<?php echo $this->translate('手机验证码不正确'); ?>" placeholder="<?php echo $this->translate('输入手机验证码'); ?>">
								<input type="button" id="get_phone_captcha" value="<?php echo $this->translate('获取验证码'); ?>">
								<input type="hidden" name="<?php echo $this->captcha_csrf['name']; ?>" id="<?php echo $this->captcha_csrf['name']; ?>" value="<?php echo $this->captcha_csrf['value']; ?>">
							</li>
						<?php } ?>
					<?php } ?>

					<?php if($this->user_reg_extend['inputArray']) {
						foreach($this->user_reg_extend['inputArray'] as $exValue) {
							?>
							<li>
								<?php if($exValue['field_type'] == 'radio' and !empty($exValue['body'])) {
									foreach($exValue['body'] as $g_b_value) {
										?>
										<input type="radio" name="<?php echo $exValue['name']; ?>" value="<?php echo $g_b_value[0]; ?>"><?php echo $g_b_value[1]; ?>&nbsp;
									<?php } } ?>

								<?php if($exValue['field_type'] == 'select' and !empty($exValue['body'])) {
									echo '<select name="'.$exValue['name'].'" id="'.$exValue['id'].'" '.(!empty($exValue['not_empty']) ? 'pattern="required" alt="'.$exValue['not_empty'].'"' : '').' class="span2">';
									foreach($exValue['body'] as $g_b_value) {
										?>
										<option value="<?php echo $g_b_value[0]; ?>"><?php echo $g_b_value[1]; ?></option>
									<?php } echo '</select>'; } ?>

								<?php if($exValue['field_type'] == 'checkbox' and !empty($exValue['body'])) {
									foreach($exValue['body'] as $g_b_value) {
										?>
										<input type="checkbox" name="<?php echo $exValue['name']; ?>[]" value="<?php echo $g_b_value[0]; ?>"><?php echo $g_b_value[1]; ?>&nbsp;
									<?php } } ?>

								<?php if($exValue['field_type'] == 'text') { ?>
									<span class="perfix fa"></span><input name="<?php echo $exValue['name']; ?>" id="<?php echo $exValue['id']; ?>"  class="input" placeholder="<?php echo $exValue['field_title']; ?>" <?php if(!empty($exValue['not_empty'])) { ?>pattern="required"  alt="<?php echo $exValue['not_empty']; ?>"<?php } ?>>
								<?php } ?>

								<?php if($exValue['field_type'] == 'textarea') { ?>
									<textarea name="<?php echo $exValue['name']; ?>" id="<?php echo $exValue['id']; ?>" <?php if(!empty($exValue['not_empty'])) { ?>pattern="required"  alt="<?php echo $exValue['not_empty']; ?>"<?php } ?>></textarea>
								<?php } ?>

								<?php if($exValue['field_type'] == 'upload') { ?>
									<input type="file" name="<?php echo $exValue['name']; ?>" id="<?php echo $exValue['id']; ?>" <?php if(!empty($exValue['not_empty'])) { ?>pattern="required"  alt="<?php echo $exValue['not_empty']; ?>"<?php } ?>>
								<?php } ?>
							</li>
						<?php } } ?>

					<?php if ($this->frontwebsite()->websiteCaptchaState('user_register_captcha') == 'true') { ?>
						<li>
							<span class="perfix fa">&#xf02a;</span><input type="text" class="input-sm" name="captcha_code" id="captcha_code" pattern="\w{5}" maxlength="5" style="width: 80px;" alt="验证码不正确" placeholder="验证码"><span id="captcha_id"></span>
						</li>
					<?php } ?>
					<li>
						<dt>&nbsp;</dt><dd><input id="readme" type="checkbox" alt="<?php echo $this->translate('同意后才可注册'); ?>"><label></label><label><?php echo $this->translate('我已阅读并同意'); ?>《<a class="" id="user-license" href="javascript:;"><?php echo $this->translate('用户注册协议'); ?></a>》</label></dd>
					</li>
					<li><button class="btn btn-main " style="padding:10px 40px; width:100%"><?php echo $this->translate('同意协议，立即注册'); ?></button></li>
					<?php if($this->frontwebsite()->getUserOtherLoginState() == 'true') { ?>
						<li>
							<hr>
							<?php
							$otherLoginArray = $this->frontwebsite()->getUserOtherLoginIni();
							if(!empty($otherLoginArray)) {
								foreach($otherLoginArray as $othKey => $othValue) {
									if($othValue['login_state'] == 'true') {
										$othKey = strtolower($othKey);
										?>
										<a href="<?php echo $this->url('frontuser/default',array('action'=>'otherlogin'), array('query'=>array('login_type'=>$othKey))); ?>" style="margin-right: 8px;"><img src="<?php echo $this->basePath('public/img/login/'.$othKey.'_login.png'); ?>"></a>
										<?php
									}
								}
							}
							?>
						</li>
					<?php } ?>
				</ul>
			</form>
		</div>
	<?php } else {
		echo '<div class="simple-box "  style="width:480px;height:340px;left:18%"><div style="font-size: 20px;;padding: 20px;">'. $this->frontwebsite()->getUserIni('register_close_message') . '</div></div>';
	} ?>
</div>
<div id="license-content" style="display:none;">
	<div style="height:400px;overflow:auto">
		<?php echo nl2br($this->frontwebsite()->getUserIni('user_register_body')); ?>
	</div>
	<div class="mt10 tc"><a href="javascript:closeLicense();" class="btn btn-main"><?php echo $this->translate('同意用户注册协议'); ?></a></div>
</div>


<script type="text/javascript">
	var dlg;
	$("#user-license").on("click",function(){
		dlg = dialog({id:'license-dialog',opacity:0.3,padding:'20px 10px 10px 20px',width:900,title:'<?php echo $this->translate('用户注册协议'); ?>',content:document.getElementById('license-content'),lock:true});
		dlg.showModal();
	});
	function closeLicense(){
		$('#readme').attr("checked",'true');
		autoValidate.showMsg({id:document.getElementById('readme'),error:false,msg:''});
		dlg.close().remove();
	}


	$("input[name='user_name']").on("change",function(event){
		if(autoValidate.validate(event)){
			$.post("<?php echo $this->url('frontuser/default/user_id',array('action'=>'check','controller'=>'user','check_type'=>'user_name','user_id'=>($this->user_info ? $this->user_info->user_id : '0'))); ?>",{user_name:$(this).val()},function(data){
				if(data == 'false') {
					autoValidate.showMsg({id:document.getElementById('user_name'),error:true,msg:'<?php echo $this->translate('该会员名已经存在！'); ?>'});
				}
			});
		}
	});
	<?php if ($userEmailRegisterState == 'true') { ?>
	$("input[name='user_email']").on("change",function(event){
		if(autoValidate.validate(event)){
			$.post("<?php echo $this->url('frontuser/default/user_id',array('action'=>'check','controller'=>'user','module'=>'user','check_type'=>'user_email','user_id'=>($this->user_info ? $this->user_info->user_id : '0'))); ?>",{user_email:$(this).val()},function(data){
				if(data == 'false') {
					autoValidate.showMsg({id:document.getElementById('user_email'),error:true,msg:'<?php echo $this->translate('该邮箱已经存在'); ?>'});
				}
			});
		}
	});
	<?php } ?>
	<?php if ($userPhoneRegisterState == 'true' and $userPhoneCaptchaState == 'true') { ?>
	$("input[name='phone_captcha']").on("change",function(event){
		if(autoValidate.validate(event)){
			$.post("<?php echo $this->url('shopfront/default/captcha-check',array('action'=>'phoneCaptcha','captcha_check'=>1)); ?>",{phone_captcha:$(this).val()},function(data){
				if(data == 'false') {
					autoValidate.showMsg({id:document.getElementById('phone_captcha'),error:true,msg:'<?php echo $this->translate('手机验证码错误！'); ?>'});
				}
			});
		}
	});
	<?php } ?>
	<?php if ($userPhoneRegisterState == 'true') { ?>
	$("input[name='user_phone']").on("change",function(event){
		if(autoValidate.validate(event)){
			$.post("<?php echo $this->url('frontuser/default/user_id',array('action'=>'check','controller'=>'user','module'=>'user','check_type'=>'user_phone','user_id'=>($this->user_info ? $this->user_info->user_id : '0'))); ?>",{user_phone:$(this).val()},function(data){
				if(data == 'false') {
					autoValidate.showMsg({id:document.getElementById('user_phone'),error:true,msg:'<?php echo $this->translate('该手机号码已经存在'); ?>'});
				}
			});
		}
	});
	<?php } ?>
	$("#readme").on("change",function(){
		if($("#readme:checked").length>0)autoValidate.showMsg({id:document.getElementById('readme'),error:false,msg:''});
		else autoValidate.showMsg({id:document.getElementById('readme'),error:true,msg:'<?php echo $this->translate('同意后才可注册'); ?>'});
	});
	function checkReadme(e){
		<?php
			if(isset($this->user_reg_extend['jsCheck']['jsCheckboxAndRadio']) and !empty($this->user_reg_extend['jsCheck']['jsCheckboxAndRadio'])) {
			echo implode('', $this->user_reg_extend['jsCheck']['jsCheckboxAndRadio']);
		} ?>

		if(e) return false;
		else{
			if($("#readme:checked").length>0)return true;
			{
				autoValidate.showMsg({id:document.getElementById('readme'),error:true,msg:'<?php echo $this->translate('同意后才可注册'); ?>'});
				return false;
			}
		}
	}
	<?php if ($this->frontwebsite()->websiteCaptchaState('user_register_captcha') == 'true') { ?>
	$("input[name='captcha_code']").on("change",function(event){
		if(autoValidate.validate(event)){
			$.post("<?php echo $this->url('shopfront/default/captcha-check',array('action'=>'captcha','captcha_check'=>1)); ?>",{captcha_code:$(this).val()},function(data){
				if(data == 'false') {
					autoValidate.showMsg({id:document.getElementById('captcha_code'),error:true,msg:'<?php echo $this->translate('验证码错误！'); ?>'});
				}
			});
		}
	});
	//验证码添加
	function captchaAdd() {
		$.get("<?php echo $this->url('shopfront/default',array('action'=>'captcha')); ?>",'',
				function(data){
					$("#captcha_id").html('<img id="captcha_img" src="<?php echo $this->basePath('/'); ?>'+data.captcha_file+'" border="0" ><a href="javascript:;" onclick="captchaAdd()"><?php echo $this->translate('换一张'); ?></a>');
				},'json');
	}
	captchaAdd();
	<?php } ?>

	<?php if ($userPhoneRegisterState == 'true' and $userPhoneCaptchaState == 'true') { ?>
	var waittime=<?php echo $this->frontwebsite()->websiteCaptchaState('phone_captcha_time'); ?>;
	function captchatime() {
		if (waittime == 0) {
			$('#user_phone').removeAttr("readonly");

			$('#get_phone_captcha').removeAttr("disabled");
			$('#get_phone_captcha').val('<?php echo $this->translate('获取验证码'); ?>');
			waittime = <?php echo $this->frontwebsite()->websiteCaptchaState('phone_captcha_time'); ?>;
		}
		else {
			$('#get_phone_captcha').val("<?php echo $this->translate('重新获取'); ?>(" + waittime + ")");
			waittime--;
			setTimeout(function() {
						captchatime()
					},
					1000)
		}
	}
	document.getElementById("get_phone_captcha").onclick=function(){
		$.ajax({
			type : 'POST',
			url	 : '<?php echo $this->url('shopfront/default',array('action'=>'phoneCaptcha')); ?>',
			data : "user_phone="+$('#user_phone').val()+"&checkrepeat=true&captcha_security="+$('#captcha_security').val(),
			success: function(msg){
				if(msg != '') {
					alert(msg);
					return false;
				} else {
					$('#user_phone').attr("readonly", true);
					$('#get_phone_captcha').attr("disabled", true);
					captchatime();
				}
			}
		});
	}
	<?php } ?>
</script>